package com.topscore.uke.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.Window;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.topscore.uke.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 71468 on 2018/3/15.
 */

public class ShareDialog extends Dialog {

    @Bind(R.id.share_wechat)
    RelativeLayout shareWechat;
    @Bind(R.id.share_moment)
    RelativeLayout shareMoment;


    private Context mContext;
    private OnShareSelectedListener mOnShareSelectedListener;


    public ShareDialog(@NonNull Context context) {
        super(context);
        this.mContext = context;
    }

    public ShareDialog(@NonNull Context context, OnShareSelectedListener onShareSelectedListener) {
        super(context);
        this.mContext = context;
        this.mOnShareSelectedListener = onShareSelectedListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Window window = getWindow();

        window.setWindowAnimations(R.style.DialogBottomAnimation);
        window.setGravity(Gravity.CENTER);
        window.requestFeature(Window.FEATURE_NO_TITLE);
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        setContentView(R.layout.share_dialog);
        ButterKnife.bind(this);

        shareWechat.setOnClickListener(view -> {
            if (mOnShareSelectedListener != null) {
//                mOnShareSelectedListener.onSelected(SHARE_MEDIA.WEIXIN);
                dismiss();
            } else {
                Toast.makeText(mContext, "请设置选择回调监听接口", Toast.LENGTH_SHORT).show();
                throw new NullPointerException();
            }
        });
        shareMoment.setOnClickListener(view -> {
            if (mOnShareSelectedListener != null) {
//                mOnShareSelectedListener.onSelected(SHARE_MEDIA.WEIXIN_CIRCLE);
                dismiss();
            } else {
                Toast.makeText(mContext, "请设置选择回调监听接口", Toast.LENGTH_SHORT).show();
                throw new NullPointerException();
            }
        });

    }

    public ShareDialog setOnShareSelectedListener(OnShareSelectedListener onShareSelectedListener) {
        this.mOnShareSelectedListener = onShareSelectedListener;
        return this;
    }

    public interface OnShareSelectedListener {
//        void onSelected(SHARE_MEDIA share_media);
    }
}
